//加载当前菜单的子菜单列表
$(function(){
	$("#dataTable").bootstrapTable({ 
	url: JSSYSMANAGERV1 + "/menu/menuList.json",
	method:"get", 
	pagination:true,
	//sidePagination:"server",
	queryParams: function(params) {
		var ps = {};
		var formParams = $("#dataForm").serializeArray(); 
		if (formParams!=null && formParams.length>0) {
			for (var fp in formParams) {
				ps[formParams[fp].name]=formParams[fp].value;
			}
		}
        return $.extend({}, params, ps);      
	}
	}); 
})
//修改菜单
function update(){
	var menuType = $("input[name='menuType']").val();
	if (menuType == 2) {
		//二级菜单
		var parentId = $("#parentId").val();
		if (!CheckUtil.isNotNull(parentId)) {
			layer.msg("请选择父节点!");
    		return;
		}
	}
	var menuName = $("input[name='menuName']").val();
	if (!CheckUtil.isNotNull(menuName)) {
		layer.msg("请输入菜单名称!");
		return;
	}
	var orderNum = $("input[name='orderNum']").val();
	if (!CheckUtil.isNotNull(orderNum) || !CheckUtil.isInt(orderNum, "+")) {
		layer.msg("请输入正确的排序编号!");
		return;
	}
	if (menuType == 1) {
		//一级菜单
//		var openFlag = $("#openFlag").val();
//		if (!CheckUtil.isNotNull(openFlag)) {
//			layer.msg("请选择是否展开!");
//    		return;
//		}
	}
	if (menuType == 2) {
		//二级菜单和按钮
		var menuUrl = $("input[name='menuUrl']").val();
		if (!CheckUtil.isNotNull(menuUrl)) {
			layer.msg("请输入链接路径!");
    		return;
		}
	}
	parent.layer.confirm('您确认修改菜单吗？', {
   		btn: ['确认', '取消'] //可以无限个按钮
   		},
   		function(){
   			$('#dataForm').submit();
   		}, 
   		function(){
   		   return;
   		}
   	);
}
//添加按钮
function addButton(rowId){
	parent.layer.open({
    type: 2,
  	title: "添加按钮",
  	area: ['450px', '320px'],
  	content: JSSYSMANAGERV1 + '/menu/addButtonShow?rowId='+rowId 
    });
}
//添加菜单
function addMenu(){
	parent.layer.open({
	type: 2,
  	title: "添加菜单",
  	area: ['450px', '400px'],
  	content: JSSYSMANAGERV1 + '/menu/addMenuShow'
	});
}

function iconFormatter(value, row, index){
	return '<span class="'+value +'"></span>';
}
function buttonFormatter(value, row, index) {
	var e = "<button id='btn_edit' type='button' onclick='deleteEmp("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span>删除</button>";
	return e;
}
//删除菜单(按钮)
function deleteEmp(rowId){
	var descStr = "【删除】";
	parent.layer.confirm('您确认'+descStr+'?', {
		btn: ['确认', '取消']  
	}, 
	function(){
		var url = JSSYSMANAGERV1 + "/menu/deleteSysmenu?rowId="+rowId;
    	$.post(url,null,function(data){
  		    if (data == 1) { 
  		   		parent.layer.alert(descStr+"成功", {icon: 1});
  		   		parent.location.reload();
  			} else if (data == 2) {
  				parent.layer.alert(descStr+"失败,请先删除该菜单下的子菜单(子按钮)!", {icon: 5});
  			} else {
  				parent.layer.alert(descStr+"失败", {icon: 5});
  			}
		});
	}, 
	function(){ 
		return;
	});
}

/*bootstrap table点击行事件*/
$(function(){
	 $("body").on("click","table>tbody>tr",function(){
      $(this).css("background","#e1ecf1").siblings().css("background","");
   });
})